// 功能一：记录鼠标的坐标
import { reactive } from 'vue'

const position = reactive({
  x: 0,
  y: 0
})

// 控制鼠标的变化
const move = (e) => {
  position.x = e.clientX
  position.y = e.clientY
}

// 组件挂载成功后监听鼠标的移动
const bindEvent = () => {
  document.addEventListener('mousemove', move)
}

// 组件卸载的时候解绑事件
const unbindEvent = () => {
  document.removeEventListener('mousemove', move)
}

export default {
  position,
  bindEvent,
  unbindEvent
}
